﻿using System;
using System.Collections.Generic;
using System.Xml;
using umbraco.MacroEngines;

namespace uComponents.RazorModels.MultipleTextstring
{
	[RazorDataTypeModel("BCE5E3EF-F15A-4484-8E56-38174FEFD579")]
	public class MultipleTextstringModelBinder : IRazorDataTypeModel
	{
		public bool Init(int CurrentNodeId, string PropertyData, out object instance)
		{
			var xml = new XmlDocument();
			xml.LoadXml(PropertyData);

			var values = new List<string>();
			foreach (XmlNode node in xml.SelectNodes("/values/value"))
			{
				values.Add(node.InnerText);
			}

			instance = values;

			return true;
		}
	}
}
